<?php
require_once "getData.php";
require_once "date.php";
#echo '本周开始日期：',$now_start,'<br />';
#echo '本周结束日期：',$now_end,'<br />';
#echo '上周开始日期：',$last_start,'<br />';
#echo '上周结束日期：',$last_end,'<br />';
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$a_name = "云计算系";
$b_name = "计算机系";
$c_name = "电工系";
$d_name = "微电系";
$dept_a = 0;
$dept_b = 0;
$dept_c = 0;
$dept_d = 0;
$perDay = 0;
$maxDay = 0;
$maxDept = "无";
$sumMonth = 0;
$Mon = 0;
$Tue = 0;
$Wed = 0;
$Thu = 0;
$Fri = 0;
$Sat = 0;
$Sun = 0;
$l_Mon = 0;
$l_Tue = 0;
$l_Wed = 0;
$l_Thu = 0;
$l_Fri = 0;
$l_Sat = 0;
$l_Sun = 0;
$offen = 0;
$olddata = 0;
$yes = 0;
$qi = 0;
$ba = 0;
$jiu = 0;
$shi = 0;
$shiyi = 0;
$shier = 0;
$shisan = 0;
$shisi = 0;
$shiwu = 0;
$shiliu = 0;
$shiqi = 0;
$shiba = 0;
$shijiu = 0;
$l_qi = 0;
$l_ba = 0;
$l_jiu = 0;
$l_shi = 0;
$l_shiyi = 0;
$l_shier = 0;
$l_shisan = 0;
$l_shisi = 0;
$l_shiwu = 0;
$l_shiliu = 0;
$l_shiqi = 0;
$l_shiba = 0;
$l_shijiu = 0;
if($result->num_rows > 0){
	while($row = $result->fetch_assoc()){
		$data = json_decode($row["data"]);
		foreach( $data as $i)
		{
			if($i->range > 1500)
			{
				break;
			}
			foreach( $olddata as $o )
			{
				if($i->mac == $o->mac)
				{
					$yes = 1;
					break;
				}
			}
			if($yes != 1)
			{
				$sumMonth = $sumMonth + 1;
				if((int)($row["timedata"]/1000)>strtotime("$last_start")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 1 days"))
				{
					$l_Mon = $l_Mon + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$last_start + 1 days")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 2 days"))
				{
					$l_Tue = $l_Tue + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$last_start + 2 days")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 3 days"))
				{
					$l_Wed = $l_Wed + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$last_start + 3 days")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 4 days"))
				{
					$l_Thu = $l_Thu + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$last_start + 4 days")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 5 days"))
				{
					$l_Fri = $l_Fri + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$last_start + 5 days")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 6 days"))
				{
					$l_Sat = $l_Sat + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$last_start + 6 days")&&(int)($row["timedata"]/1000)<strtotime("$last_start + 7 days"))
				{
					$l_Sun = $l_Sun + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 1 days"))
				{
					$Mon = $Mon + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start + 1 days")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 2 days"))
				{
					$Tue = $Tue + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start + 2 days")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 3 days"))
				{
					$Wed = $Wed + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start + 3 days")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 4 days"))
				{
					$Thu = $Thu + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start + 4 days")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 5 days"))
				{
					$Fri = $Fri + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start + 5 days")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 6 days"))
				{
					$Sat = $Sat + 1;
				}
				if((int)($row["timedata"]/1000)>strtotime("$now_start + 6 days")&&(int)($row["timedata"]/1000)<strtotime("$now_start + 7 days"))
				{
					$Sun = $Sun + 1;
				}

				if((int)($row["timedata"]/1000)>($start+60*60*7)&&(int)($row["timedata"]/1000)<($start+60*60*8))
				{
					$qi = $qi + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*8)&&(int)($row["timedata"]/1000)<($start+60*60*9))
				{
					$ba = $ba + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*9)&&(int)($row["timedata"]/1000)<($start+60*60*10))
				{
					$jiu = $jiu + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*10)&&(int)($row["timedata"]/1000)<($start+60*60*11))
				{
					$shi = $shi + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*11)&&(int)($row["timedata"]/1000)<($start+60*60*12))
				{
					$shiyi = $shiyi + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*12)&&(int)($row["timedata"]/1000)<($start+60*60*13))
				{
					$shier = $shier + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*13)&&(int)($row["timedata"]/1000)<($start+60*60*14))
				{
					$shisan = $shisan + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*14)&&(int)($row["timedata"]/1000)<($start+60*60*15))
				{
					$shisi = $shisi + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*15)&&(int)($row["timedata"]/1000)<($start+60*60*16))
				{
					$shiwu = $shiwu + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*16)&&(int)($row["timedata"]/1000)<($start+60*60*17))
				{
					$shiliu = $shiliu + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*17)&&(int)($row["timedata"]/1000)<($start+60*60*18))
				{
					$shiqi = $shiqi + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*18)&&(int)($row["timedata"]/1000)<($start+60*60*19))
				{
					$shiba = $shiba + 1;
				}
				if((int)($row["timedata"]/1000)>($start+60*60*19)&&(int)($row["timedata"]/1000)<($start+60*60*20))
				{
					$shijiu = $shijiu + 1;
				}

				if((int)($row["timedata"]/1000)>($start-86400+60*60*7)&&(int)($row["timedata"]/1000)<($start-86400+60*60*8))
				{
					$l_qi = $l_qi + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*8)&&(int)($row["timedata"]/1000)<($start-86400+60*60*9))
				{
					$l_ba = $l_ba + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*9)&&(int)($row["timedata"]/1000)<($start-86400+60*60*10))
				{
					$l_jiu = $l_jiu + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*10)&&(int)($row["timedata"]/1000)<($start-86400+60*60*11))
				{
					$l_shi = $l_shi + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*11)&&(int)($row["timedata"]/1000)<($start-86400+60*60*12))
				{
					$l_shiyi = $l_shiyi + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*12)&&(int)($row["timedata"]/1000)<($start-86400+60*60*13))
				{
					$l_shier = $l_shier + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*13)&&(int)($row["timedata"]/1000)<($start-86400+60*60*14))
				{
					$l_shisan = $l_shisan + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*14)&&(int)($row["timedata"]/1000)<($start-86400+60*60*15))
				{
					$l_shisi = $l_shisi + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*15)&&(int)($row["timedata"]/1000)<($start-86400+60*60*16))
				{
					$l_shiwu = $l_shiwu + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*16)&&(int)($row["timedata"]/1000)<($start-86400+60*60*17))
				{
					$l_shiliu = $l_shiliu + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*17)&&(int)($row["timedata"]/1000)<($start-86400+60*60*18))
				{
					$l_shiqi = $l_shiqi + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*18)&&(int)($row["timedata"]/1000)<($start-86400+60*60*19))
				{
					$l_shiba = $l_shiba + 1;
				}
				if((int)($row["timedata"]/1000)>($start-86400+60*60*19)&&(int)($row["timedata"]/1000)<($start-86400+60*60*20))
				{
					$l_shijiu = $l_shijiu + 1;
				}
				$resulta = $conn->query($depta);
				if($resulta->num_rows > 0)
				{
					while($mac = $resulta->fetch_assoc())
					{
						if($i->mac == $mac["mac"])
						{
							$dept_a = $dept_a + 1;
							break;
						}
					}
				}
				$resultb = $conn->query($deptb);
				if($resultb->num_rows > 0)
				{
					while($mac = $resultb->fetch_assoc())
					{
						if($i->mac == $mac["mac"])
						{
							$dept_b = $dept_b + 1;
							break;
						}
					}
				}
				$resultc = $conn->query($deptc);
				if($resultc->num_rows > 0)
				{
					while($mac = $resultc->fetch_assoc())
					{
						if($i->mac == $mac["mac"])
						{
							$dept_c = $dept_c + 1;
							break;
						}
					}
				}
				$resultd = $conn->query($deptd);
				if($resultd->num_rows > 0)
				{
					while($mac = $resultd->fetch_assoc())
					{
						if($i->mac == $mac["mac"])
						{
							$dept_d = $dept_d + 1;
							break;
						}
					}
				}
			}else
			{
				$yes = 0;
				$offen = $offen + 1;
			}
		}
		$olddata = $data;
	}
}else{
}
$maxDay = max($Mon,$Tue,$Wed,$Thu,$Fri,$Sat,$Sun);
$maxDept = max($dept_a,$dept_b,$dept_c,$dept_d);
if($maxDept == $dept_a){$maxDept = $a_name;}
if($maxDept == $dept_b){$maxDept = $b_name;}
if($maxDept == $dept_c){$maxDept = $c_name;}
if($maxDept == $dept_d){$maxDept = $d_name;}
$offen = (int)($offen/100);
$perDay = (int)($sumMonth/30);
$conn->close();
?>
